package com.ybfenpan.controller.admin.info;


import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Admin;
import com.ybfenpan.model.Notice;
import com.ybfenpan.service.NoticeService;
import com.ybfenpan.utils.ContextUtil;
import com.ybfenpan.utils.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.util.HtmlUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;


/**
 * Created by Administrator on 2016/3/25.
 */
@Controller
 
public class NoticeAddController extends BaseController {
    @Resource
    private NoticeService noticeService;
   
   
    @RequestMapping("admin/info/noticeAdd.shtml")
    public String add(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws Exception{
    	
		//新增
    	Admin admin = ContextUtil.getAdmin();
    	
    	  
    	Map formMap = getParameterMap(request);
    	String title = MapUtil.getString(formMap, "title");
    	String content = MapUtil.getString(formMap, "content");
    	String commitDateString = MapUtil.getString(formMap, "commitDate");
    	Date commitDate=  null;
    	if(commitDateString!=null&&!commitDateString.equals("")){
    		System.out.println("进入");
    		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟  
    	   	 
        	commitDate=sdf.parse(commitDateString);  
    	}else{
    		System.out.println("不进入");
    		commitDate = new Date();
    	}
    	System.out.println(commitDate);
    	
      
    	Notice one=new Notice();
		one.setTop(10);
		one.setTitle(title);
		one.setContent(HtmlUtils.htmlUnescape(content));
		one.setAdminId(admin.getId());
		one.setFileNum(0);
		one.setCommitDate(commitDate);
		one.setNewDate(commitDate);
		noticeService.saveOrUpdate(one);
		
        return "redirect:noticeList.shtml";
        
    }
  
}
